package _01Collection接口;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.LinkedList;

/*

 boolean add(E e) 
          纭繚姝� collection 鍖呭惈鎸囧畾鐨勫厓绱狅紙鍙�夋搷浣滐級銆� 
 boolean addAll(Collection<? extends E> c) 
          灏嗘寚瀹� collection 涓殑鎵�鏈夊厓绱犻兘娣诲姞鍒版 collection 涓紙鍙�夋搷浣滐級銆� 
 void clear() 
          绉婚櫎姝� collection 涓殑鎵�鏈夊厓绱狅紙鍙�夋搷浣滐級銆� 
 boolean contains(Object o) 
          濡傛灉姝� collection 鍖呭惈鎸囧畾鐨勫厓绱狅紝鍒欒繑鍥� true銆� 
 boolean containsAll(Collection<?> c) 
          濡傛灉姝� collection 鍖呭惈鎸囧畾 collection 涓殑鎵�鏈夊厓绱狅紝鍒欒繑鍥� true銆� 
 boolean equals(Object o) 
          姣旇緝姝� collection 涓庢寚瀹氬璞℃槸鍚︾浉绛夈�� 
 int hashCode() 
          杩斿洖姝� collection 鐨勫搱甯岀爜鍊笺�� 
 boolean isEmpty() 
          濡傛灉姝� collection 涓嶅寘鍚厓绱狅紝鍒欒繑鍥� true銆� 
 Iterator<E> iterator() 
          杩斿洖鍦ㄦ collection 鐨勫厓绱犱笂杩涜杩唬鐨勮凯浠ｅ櫒銆� 
 boolean remove(Object o) 
          浠庢 collection 涓Щ闄ゆ寚瀹氬厓绱犵殑鍗曚釜瀹炰緥锛屽鏋滃瓨鍦ㄧ殑璇濓紙鍙�夋搷浣滐級銆� 
 boolean removeAll(Collection<?> c) 
          绉婚櫎姝� collection 涓偅浜涗篃鍖呭惈鍦ㄦ寚瀹� collection 涓殑鎵�鏈夊厓绱狅紙鍙�夋搷浣滐級銆� 
 boolean retainAll(Collection<?> c) 
          浠呬繚鐣欐 collection 涓偅浜涗篃鍖呭惈鍦ㄦ寚瀹� collection 鐨勫厓绱狅紙鍙�夋搷浣滐級銆� 
 int size() 
          杩斿洖姝� collection 涓殑鍏冪礌鏁般�� 
 Object[] toArray() 
          杩斿洖鍖呭惈姝� collection 涓墍鏈夊厓绱犵殑鏁扮粍銆� 
<T> T[] 
 toArray(T[] a) 
          杩斿洖鍖呭惈姝� collection 涓墍鏈夊厓绱犵殑鏁扮粍锛涜繑鍥炴暟缁勭殑杩愯鏃剁被鍨嬩笌鎸囧畾鏁扮粍鐨勮繍琛屾椂绫诲瀷鐩稿悓銆� 

 * */
public class CollectionDemo {

    public static void main(String[] args) {
//		Collection c1 = new Collection(); 鎶ラ敊

        Collection c1 = new ArrayList();
        c1.add(1);
        c1.add("寮犱笁");
        c1.add('6');
        System.out.println(c1);

        Collection c2 = new LinkedList();
        c2.add("寮犱笁");
        c2.add("鏉庡洓");
        c2.add("鐜嬩簲");
        System.out.println(c2);


        // 娉涘瀷<>
        // 鍙兘瀛樺偍<>鍐呭埗瀹氱被鍨嬬殑鏁版嵁
        Collection<String> collection = new ArrayList<>();
        collection.add("寮犱笁");
//		collection.add(1); 鎶ラ敊


        Collection c5 = new ArrayList();
        c5.add(c1);
        c5.add(c2);
        System.out.println(c5);


        // 绉婚櫎 remove
//		 boolean remove(Object o) 
//       	浠庢 collection 涓Щ闄ゆ寚瀹氬厓绱犵殑鍗曚釜瀹炰緥锛屽鏋滃瓨鍦ㄧ殑璇濓紙鍙�夋搷浣滐級銆� 
//       boolean removeAll(Collection<?> c) 
//       	绉婚櫎姝� collection 涓偅浜涗篃鍖呭惈鍦ㄦ寚瀹� collection 涓殑鎵�鏈夊厓绱狅紙鍙�夋搷浣滐級銆�

        c2.remove("寮犱笁");
        System.out.println(c2);

        c2.add("鍒樺");
        System.out.println(c2);
        c2.removeAll(c1);
        System.out.println(c2);

        //浜ら泦 retainAll
//		 boolean retainAll(Collection<?> c) 
//       	浠呬繚鐣欐 collection 涓偅浜涗篃鍖呭惈鍦ㄦ寚瀹� collection 鐨勫厓绱狅紙鍙�夋搷浣滐級銆� 
        Collection<String> c6 = new ArrayList<>();
        c6.add("寮犱笁");
        c6.add("閲屾柉");
        c6.add("閲屾柉");
        c6.add("鐜嬩簲");
        c6.add("璧靛叚");

        Collection<String> c7 = new ArrayList<>();
        c7.add("寮犱笁");
        c7.add("鍒樺");
        c7.add("鐜嬩簲");
        c7.add("鏇规搷");

        c6.retainAll(c7);
        System.out.println("retainAll锛�" + c6);

        //澶у皬闀垮害  size
        System.out.println("澶у皬:" + c7.size());

        //娓呯┖ clear
        c6.clear();
        System.out.println("澶у皬锛�" + c6.size());

        //杞负鏁扮粍
        Object[] str = c7.toArray();
        System.out.println(Arrays.toString(str));
    }

}
